<?php
include_once('admin_global.php');
$theme->add_block('body');
$up=new bn_upload;
if(empty($_GET['type']) or empty($_GET['func']))
die();
if(!empty($_FILES['upload']))
    echo $up->upload_user($_FILES['upload'],$login->get_user_id(),$_GET['type']);

if(!empty($_POST['delete']))
{
    $arr=$_POST['select'];
    if(!empty($arr))
    {
        $keys=array_keys($arr);
        foreach($keys as $key)
        {
          $up->delete($key);  
        }
    }
}

?>
<form method="post" enctype="multipart/form-data">
<input type="file" accept="text/html" size="60" name="upload"/>
<input type="submit" name="save" value="<?= $lang[15]?>" class="button blue"/>
</form>
<form method="post" enctype="multipart/form-data">
<div id="show">
<?php
$grid=new bn_grid;
$cid=new column;
$grid->header->enable=true;
$cid->field_name='id';
$cid->hide=true;
$grid->columns->append($cid);
$curl=new column;
$curl->caption=$lang[85];
$curl->field_name='url';
$grid->columns->append($curl);
$fname=new column;
$fname->caption=$lang[56];
$fname->field_name='m_filename';
$grid->columns->append($fname);
$cdel=new column;
$cdel->caption=$lang[86]; 
$cdel->template="{$lang[86]}<input type='checkbox' name='select[<%id%>]'/>";	
$grid->columns->append($cdel);
$grid->show($up->select_user($login->get_user_id())->fetch());
?>
</div>
<input type="submit" name="delete" value="<?= $lang[11] ?>" onclick="return confirm('<?= $lang[10] ?>')" class="button red"/>
</form>
<script type="text/javascript">
function send_param()
{
    var td='';
      $('td').find(':checkbox').each(function(){
        if($(this).attr('checked'))
        {
            td=[$(this).closest('tr').children(':eq(1)').html()+'|'+$(this).closest('tr').children(':eq(2)').html()]+','+td; 
        }
    });
    td=td.substring(0, td.length - 1);
    window.opener.<?= $_GET['func'] ?>(td);
    window.close();
}
</script>
<input type="submit" name="select" value="<?= $lang[86]?>" onclick="send_param()" class="button"/>
<?php
	$theme->render();
?>